package com.xjggb.io;

import java.io.*;

public class Demo04 {
    static String  fir= "D:\\lu\\1.txt";

    public static void main(String[] args) {
        show2();
    }

    //读取操作
    public static void show2(){
        //创建io流
        FileInputStream stream = null;
        BufferedInputStream bufferedOutputStream =null;
        try {
            stream = new FileInputStream(fir);
            // 创建字节缓冲输出流
            bufferedOutputStream = new BufferedInputStream(stream);

            int b;
            while ((b = bufferedOutputStream.read()) != -1) {
                System.out.println((char)b);
            }


        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                bufferedOutputStream.close();
                stream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }

        }



    }


    public static void show1(){
        //创建io流
        FileOutputStream stream = null;
        BufferedOutputStream bufferedOutputStream =null;
        try {
            stream = new FileOutputStream(fir,false);
            // 创建字节缓冲输出流
             bufferedOutputStream = new BufferedOutputStream(stream);
            //写入数据
            final byte[] bytes = "来了老弟".getBytes();
            bufferedOutputStream.write(bytes);

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                bufferedOutputStream.close();
                stream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }

        }



    }
}
